<template>
  <div class="main">
    <div class="recommendPage"  @mouseenter="onMouseEnter" @mouseleave="onMouseLeave">
      <swiper
        :options="swiperOption"
        ref="mySwiper"
       
      >
        <swiper-slide><img src="../../assets/a.jpg" alt="" /></swiper-slide>
        <swiper-slide><img src="../../assets/b.jpg" alt="" /></swiper-slide>
        <swiper-slide><img src="../../assets/c.jpg" alt="" /></swiper-slide>
        <div class="swiper-pagination" slot="pagination"></div>
        <div class="swiper-button-prev" slot="button-prev"></div>
        <div class="swiper-button-next" slot="button-next"></div>
      </swiper>
    </div>
    <div class="conter">
      <el-input
        class="input"
        placeholder="请输入想搜索的房产"
        v-model="input"
        @keydown.enter.native="search"
      >
        <i
          slot="suffix"
          class="el-input__icon el-icon-search"
          @click="search"
        ></i>
      </el-input>
    </div>
  </div>
</template>

<script>
import { swiper, swiperSlide } from "vue-awesome-swiper";
import "swiper/dist/css/swiper.css";
export default {
  components: {
    swiper,
    swiperSlide,
  },
  data() {
    return {
      input: "",
      swiperOption: {
        loop: true,
        autoplay: {
          delay: 3000,
          stopOnLastSlide: false,
          disableOnInteraction: true,
        },
        // 显示分页
        pagination: {
          el: ".swiper-pagination",
          clickable: true, //允许分页点击跳转
        },
        // 设置点击箭头
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
      },
    };
  },
  methods: {
    search() {
      if (this.input) {
        this.$router.push({
          path: "/list",
          query: {
            title_contains: this.input,
          },
        });
      } else {
        this.$message.warning("请输入搜索关键字");
      }
    },
    onMouseEnter(){
      console.log('11');
      this.$refs.mySwiper.swiper.autoplay.stop()
    },
    onMouseLeave(){
      this.$refs.mySwiper.swiper.autoplay.start()
    }
    //通过获得的swiper对象来暂停自动播放
  },
};
</script>

<style lang="less" scoped>
.main {
  position: relative;
}
.search {
  position: relative;
  width: 100%;
  height: 700px;
  background: url("../../assets/309419.jpg") no-repeat;
  background-size: 100% 100%;
}
.conter {
  width: 502px;
  height: 60px;
  // background-color: red;
  margin: auto;
  position: absolute;
  z-index: 99;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
/deep/.el-input__inner,
.el-input {
  width: 500px;
  height: 45px;
  background-color: #ffffff;
  border-radius: 27.5px;
  padding-right: 0;
  border: 0;
}
.input {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #ffffff;
  padding-right: 0;
  border: 0;
  .el-icon-search {
    margin-right: -6px;
    font-size: 20px;
    line-height: 45px;
    width: 50px;
    color: #fff;
    cursor: pointer;
    text-align: center;
    font-weight: 700;
    background-color: #5591bd;
    border-top-right-radius: 27.5px;
    border-bottom-right-radius: 27.5px;
    border-bottom-left-radius: 27.5px;
  }
}
.recommendPage .swiper-container {
  position: relative;
  width: 100%;
  height: 700px;
  background: pink;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
.recommendPage .swiper-container .swiper-slide {
  width: 100%;
  line-height: 200px;
  background: yellowgreen;
  color: #000;
  font-size: 16px;
  text-align: center;
}
.swiper-button-next,
.swiper-button-prev {
  opacity: 0.5;
}
</style>
